﻿import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2


Rectangle {
    id: idComboOrder;
    width: 1000;
    height: 700;

    Button {
        id: idBtn;
        text: "遍历";
        width: 100;
        height: 30;
        onClicked: {
            for (var i = 0 ; i < idModelTickerData.count ; ++i) {
                console.log(idModelTickerData.get(i).checked + "," + idModelTickerData.get(i).ticker);
            }
        }
    }

    TableView {
        id: idTblBasketTicker;
        anchors.fill: parent;
        anchors.topMargin: 35;
        style: TableViewStyle {
            headerDelegate: Rectangle {
                height: textItem.implicitHeight * 1.2
                width: textItem.implicitWidth
                color: "lightsteelblue"
                CheckBox{
                    id:firstBox
                    width: 45
                    height: 30
                    anchors.centerIn: parent
                    visible: styleData.column === 0
                    onClicked: {
                        console.log("-----------clicked "+firstBox.checked)
                    }
                }
                Text {
                    id: textItem
                    anchors.fill: parent
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: styleData.textAlignment
                    anchors.leftMargin: 12
                    text: styleData.value
                    elide: Text.ElideRight
                    color: textColor
                    renderType: Text.NativeRendering
                    visible: styleData.column !== 0
                    z:styleData.column !== 0?0:1
                }
                Rectangle {
                    anchors.right: parent.right
                    anchors.top: parent.top
                    anchors.bottom: parent.bottom
                    anchors.bottomMargin: 1
                    anchors.topMargin: 1
                    width: 1
                    color: "#ccc"
                }
            }
        }
        TableViewColumn {
            id: idCheckBox;
            role: "checked";
            width: 45;
            title:""
            resizable: false;
            delegate: Rectangle{
                id: idRectCheck;
                color: "transparent";
                CheckBox {
                    id: idCheckItem;
                    checked: idModelTickerData.get(styleData.row).checked
                    anchors.centerIn: parent;
                    onCheckedChanged: {
                        console.log("checked ",idCheckItem.checked)
                        console.log("row ",styleData.row)
                        idModelTickerData.setProperty(styleData.row, "checked", idCheckItem.checked);
                    }
                }
            }
        }
        TableViewColumn {
            id: idTicker;
            title: qsTr("证券代码");
            role: "ticker";
            width: 100;
        }
        TableViewColumn {
            id: idTicker2;
            title: qsTr("证券名称");
            role: "stockName";
            width: 100;
        }

        ListModel {
            id: idModelTickerData;
            ListElement { ticker:"000001";checked:true;stockName:"平安证券" }
            ListElement { ticker:"600000"; checked:false;stockName:"XX证券"}
            ListElement { ticker:"002673";checked:false ;stockName:"FUCK证券"}
            ListElement { ticker:"601688";checked:false;stockName:"华泰证券" }
        }
        model: idModelTickerData;
    }



}// end idComboOrder
